﻿using System;
using System.Windows.Forms;
using Facebook.Schema;
using Facebook.Winforms;
using FBToolkit.Samples.Winforms.Properties;
using System.Collections.Generic;
using Facebook.Schema.Graph;

namespace WinformsSample
{
	public partial class FriendViewer : Form
	{
		public FriendViewer()
		{
			InitializeComponent();
			facebookService1.ApplicationKey = Settings.Default.api_key;
            facebookService1.ConnectToFacebook(new List<Enums.ExtendedPermissions>() { Enums.ExtendedPermissions.read_stream, Enums.ExtendedPermissions.publish_stream});
		}

		private void TestService_Load(object sender, EventArgs e)
		{
			ListenToEvents(true);
			try
			{
                var me = facebookService1.Users.GetInfo();
                var me2 = facebookService1.Api.Graph.Post<FacebookUser>("rpowers119", new Dictionary<string, string>() { { "metadata", "1" } });
                var f2 = facebookService1.Api.Graph.Post<FacebookUserCollection>("me/friends", null);
                var f3 = facebookService1.Api.Graph.Post<FacebookPostCollection>("me/home", null);
                var f4 = facebookService1.Api.Graph.Post<FacebookPostCollection>("me/feed", null);
                var f5 = facebookService1.Api.Graph.Post<FacebookPostCollection>("me/tagged", null);
                var f6 = facebookService1.Api.Graph.Post<FacebookPostCollection>("me/posts", null);
                var f8 = facebookService1.Api.Graph.Post<FacebookItemCollection>("me/activities", null);
                var f9 = facebookService1.Api.Graph.Post<FacebookItemCollection>("me/interests", null);
                var f10 = facebookService1.Api.Graph.Post<FacebookItemCollection>("me/music", null);
                var f11 = facebookService1.Api.Graph.Post<FacebookItemCollection>("me/books", null);
                var f12 = facebookService1.Api.Graph.Post<FacebookItemCollection>("me/movies", null);
                var f13 = facebookService1.Api.Graph.Post<FacebookItemCollection>("me/television", null);
                var f14 = facebookService1.Api.Graph.Post<FacebookItemCollection>("me/likes", null);
                var f15 = facebookService1.Api.Graph.Post<PhotoCollection>("me/photos", null);
                var f16 = facebookService1.Api.Graph.Post<AlbumCollection>("me/albums", null);
                var f17 = facebookService1.Api.Graph.Post<VideoCollection>("me/videos", null);
                var f18 = facebookService1.Api.Graph.Post<GroupCollection>("me/groups", null);
                var f19 = facebookService1.Api.Graph.Post<FacebookStatusMessageCollection>("me/statuses", null);
                var f20 = facebookService1.Api.Graph.Post<FacebookLinkCollection>("me/links", null);
                var f21 = facebookService1.Api.Graph.Post<NoteCollection>("me/notes", null);
                var f22 = facebookService1.Api.Graph.Post<FacebookEventCollection>("me/events", null);
                var friends = facebookService1.Friends.GetUserObjects();
				LoadUserBasedControls(me);
				friendList1.Friends = friends;
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
				Close();
			}
		}

		private void ListenToEvents(bool listen)
		{
			if (listen)
			{
				friendList1.FriendSelected += friendList1_FriendSelected;
			}
		}

		private void friendList1_FriendSelected(object sender, FriendSelectedEventArgs e)
		{
			LoadUserBasedControls(e.User);
		}

		private void LoadUserBasedControls(user user)
		{
			profile1.User = user;
		    photoAlbum1.Albums = facebookService1.Photos.GetAlbums(user.uid.Value);
		}
	}
}